#include<bits/stdc++.h>
using namespace std;
int a[200010],b[1000010];
int main(){
    freopen("color.in","r",stdin);
  freopen("color.out","w",stdout);
int t;
cin>>t;
while(t--){
        memset(b,0,sizeof(b));
        long long ans=0;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        b[x]++;
    }
    for(int i=1;i<=1000000;i++){
        if(b[i]>1){
                //cout<<i<<endl;
            ans=ans+(b[i]-1)*i;
        }
    }
    cout<<ans<<endl;
}
}
